public class Demo2 {
    public static void main(String[] args) {
        // 给定一个有序整型数组, 实现二分查找
        int[] arr = new int[]{1,2,3,4,5,6};

        int i = 0;
        int j = arr.length - 1;
        int target = 2;
        while(i <= j){
            int mid = i + (j - i) / 2;
            if(arr[mid] > target){
                j = mid - 1;
            }else if(arr[mid] < target){
                i = mid + 1;
            }else{
                System.out.println("下标是 = " + mid);
                break;
            }
        }
    }
}
